<template>
  <div>
    <index-cmpt :models="models"></index-cmpt>

    <submit-edit-dialog
      :visible.sync="submitVisible"
      @success="handleSubmitSuccess"
      @dismiss="submitVisible = false"
    ></submit-edit-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

import IndexCmpt from '@/bank/views/business/28/normal/IndexCmpt'
import SubmitEditDialog from '@/bank/views/fast/recommend/SubmitEditDialog'

export default {
  components: {
    IndexCmpt,
    SubmitEditDialog,
  },
  props: {},
  data() {
    return {
      submitVisible: false,
      submitStauts: 0,
    }
  },
  computed: {
    ...mapGetters(['taskCountSimple']),
    productId() {
      return this.$route.query.id || ''
    },
    models() {
      return [
        {
          title: '项目立项',
          subTitle: '待办',
          subCount: this.taskCountSimple.todo_claim_total || 0,
          url: '/res_index/mission/simple/approve',
        },
        {
          title: '资料补充',
          subTitle: '待办',
          subCount: this.taskCountSimple.todo_datum_total || 0,
          url: '/res_index/mission/simple/sign',
        },
        {
          title: '项目推荐',
          subTitle: '待办',
          subCount: this.taskCountSimple.todo_recommend_total || 0,
          url: '/res_index/mission/simple/recom',
          onclick: this.handleSubmit,
        },
        {
          title: '放款登记',
          subTitle: '待办',
          subCount: this.taskCountSimple.todo_approval_register_total || 0,
          url: '/res_index/mission/simple/register',
        },
        {
          title: '贷后管理',
          subTitle: '到期',
          subCount: this.taskCountSimple.todo_exp_total || 0,
          url: '/res_index/mission/simple/postloan',
        },
      ]
    },
  },
  watch: {
    productId: {
      handler: function () {
        this.getCount()
      },
      immediate: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    getCount() {
      this.$store.dispatch('getTaskCountSimple', this.productId)
    },
    handleSubmit() {
      this.submitVisible = true
    },
    handleSubmitSuccess() {
      this.submitVisible = false
      // 刷新
      this.$router.push({
        path: this.models[2].url,
        query: {
          id: this.productId,
          status: ++this.submitStauts,
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
